package com.ellricky.baselib.ui.visit

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.widget.refresh.RefreshFlag
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.R
import com.ellricky.baselib.adapter.visit.VisitAdapter2
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.ReturnCallback
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback
import com.ellricky.baselib.util.jump

class VisitChildFragment : BaseRefreshFragment<Void, BasePresenter<Void>, ReturnCallback>() {

    private val returnNum: String by lazy {
        arguments?.getString(BaseConstant.KEY_TYPE) ?: ""
    }

    override fun initUIView(view: View?) {
        super.initUIView(view)
        hideToolBar()
        loadDataOnInit()
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<ReturnCallback>(mContext) {
            override fun onSuccess(data: MutableList<ReturnCallback>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(data, refresh)
            }
        }
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap["action"] = getActions()
        paramMap["school_id"] = LocalCacheUtil.getSchoolId()
        paramMap["return_num"] = returnNum
        paramMap["eid"] = LocalCacheUtil.getUid()
    }

    private fun getActions(): String {
        return when (LocalCacheUtil.getCardType()) {
            BaseConstant.CARD_TEACHER_MANAGER -> {
                "gzaReturnList"
            }
            BaseConstant.CARD_PRESIDENT -> {
                "headGzaReturnList"
            }
            else -> {
                ""
            }
        }
    }

    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, i: Int, l: Long) {
        super.onItemClick(adapterView, view, i, l)
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<ReturnCallback> {
        return VisitAdapter2(returnNum)
    }

    override fun getUrlPath(): String {
        return ""
    }

    companion object {
        fun newInstance(index: String): VisitChildFragment {
            val fragment = VisitChildFragment()
            val bundle = Bundle().apply {
                putString(BaseConstant.KEY_TYPE, index)
            }
            fragment.arguments = bundle
            return fragment
        }
    }
}